#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //    QPixmap qPixmap(1500,2100);
    //    QPainter qPaintAsPixmap(&qPixmap);
    //    //使用设备中的背景色填充
    //    qPixmap.fill(Qt::white);

    //    //新增画刷填充背景色或者使用设备中的背景色填充
    //    //QBrush qBrush;
    //    //qPaint.setBrush(qBrush);
    //    //qPaint.fillRect(0,0,1500,2100,Qt::green);

    //    //将图片绘制到设备
    //    qPaintAsPixmap.drawPixmap(0,0,1500,2100,QPixmap(":/new/gif/assassins_creed_PNG78.png"));
    //    //将图片保存为文件
    //    qPixmap.save("./qPixmap.png");



    //    //生成内存图型到设备QImage，Format_ARGB32_Premultiplied透明色
    //    QImage qImage(1500,2100,QImage::QImage::Format_ARGB32_Premultiplied);
    //    QPainter qPaintAsImage(&qImage);
    //    qPaintAsImage.drawPixmap(0,0,1500,2100,QPixmap(":/new/gif/assassins_creed_PNG78.png"));

    //    //填充像素点到设备QImage
    //    for (int i = 0; i < 100; ++i) {
    //        for (int j = 0; j < 100; ++j) {
    //            qImage.setPixel(QPoint(i,j),qRgb(0,255,255));
    //        }
    //    }
    //    //保存为文件
    //    qImage.save("./qImage.png");



    //    //生成内存图型到设备QPicture
    //    QPicture qPicture;
    //    QPainter qPaintAsPicture;
    //    qPaintAsPicture.begin(&qPicture);
    //    qPaintAsPicture.drawPixmap(0,0,1500,2100,QPixmap(":/new/gif/assassins_creed_PNG78.png"));
    //    qPaintAsPicture.end();
    //    //保存为文件
    //    qPicture.save("./qPicture.png");


    //Qt::ToolTip 显示成面板
    //Qt::Popup 显示成面板
    //Qt::SplashScreen 显示成面板
    //Qt::Sheet 显示成Dialog
    //Qt::Dialog 显示成Dialog
    //Qt::Tool 只有一个关闭按钮
    //Qt::Drawer 只有一个关闭按钮
    //Qt::CoverWindow 无任何按钮，窗口无法拖动大小
    //Qt::SubWindow 无任何按钮，窗口无法拖动大小
    this->setWindowFlags(
                Qt::FramelessWindowHint
                |this->windowFlags()
                );
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setFixedSize(this->width(),this->height());
}
void MainWindow::paintEvent(QPaintEvent *event)
{
    //    QPainter* qPainter = new QPainter(this);

    QPainter* qPainter = new QPainter();
    qPainter->begin(this);
    //设置背景图
    //    qPainter->drawPixmap(0,0,this->width(),this->height(),QPixmap(QString(":/new/gif/gif/timg.gif")));
    //qPainter->drawPixmap(this->rect(),QPixmap(QString(":/new/gif/gif/timg.gif")));

    //    QPen qPen;
    //    //设置线宽
    //    qPen.setWidth(5);
    //    qPen.setColor(Qt::green);
    //设置画笔颜色rgb方式
    //qPen.setColor(QColor(235,235,235));
    //设置风格
    //    qPen.setStyle(Qt::DashLine);
    //    qPainter->setPen(qPen);


    //设置画刷
    //    QBrush qBrush;
    //    设置画刷颜色
    //    qBrush.setColor(Qt::gray);
    //    设置画刷风格
    //    qBrush.setStyle(Qt::CrossPattern);
    //    qBrush.setStyle(Qt::Dense3Pattern);
    //    qBrush.setStyle(Qt::DiagCrossPattern);
    //    qPainter->setBrush(qBrush);
    //画矩形
    //    qPainter->drawRect(this->rect());
    //画圆，QPoint指定坐标,xy指定宽度和高度
    //    qPainter->drawEllipse(QPoint(100,100),20,20);
    //    qPainter->drawLine(50,50,300,50);
    //    qPainter->drawLine(50,50,150,300);
//        qPainter->drawPixmap(x,y,30,30,QPixmap(":/new/gif/gif/timg.gif"));
    //结束绘画

    //绘图透明色的QPixmap和QBitmap
    //    QPixmap qPixmap;
    //    qPixmap.load(":/new/gif/assassins_creed_PNG78.png");
    //    qPainter->drawPixmap(0,50,200,200,qPixmap);
    //    qPainter->drawPixmap(300,50,200,200,QBitmap(":/new/gif/assassins_creed_PNG78.png"));


    //    //绘图非透明色的QPixmap和QBitmap
    //    QPixmap qPixmap1;
    //    qPixmap1.load(":/new/gif/assassins_creed_PNG781.png");
    //    qPainter->drawPixmap(0,350,200,200,qPixmap1);
    //    qPainter->drawPixmap(300,350,200,200,QBitmap(":/new/gif/assassins_creed_PNG781.png"));


    //加载QPicture设备保存的图片二进制数据到主窗口
    //    QPicture qPicture;
    //    qPicture.load("./qPicture.png");
    //    //将picture二进制数据显示到窗口
    //    qPainter->drawPicture(0,0,qPicture);


    //QPixmap 转换为 QImage
    //    QPixmap qPixmap;
    //    qPixmap.load(":/new/gif/assassins_creed_PNG78.png");
    //    QImage qImage = qPixmap.toImage();
    //    qPainter->drawImage(0,0,qImage);


    // QImage转换为 QPixmap
    QImage qImages;
    qImages.load(":/new/gif/assassins_creed_PNG78.png");
    QPixmap qPixmaps=QPixmap::fromImage(qImages);
    qPainter->drawPixmap(0,0,350,500,qPixmaps);

    qPainter->end();
}


MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    x+=50;
    if (x>=this->width()) {
        x=0;
    }
    update();
}

void MainWindow::on_pushButton_2_clicked()
{
    y+=50;
    if (y>=this->height()) {
        y=0;
    }
    update();
}
